﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

using System.Collections.Generic;
using System.Text;

public partial class OrderCart_OrderPayMethod : System.Web.UI.Page
{
    protected void Page_PreInit(object sender, EventArgs e)
    {
        Page.Theme = BLL.Common.GetWSThemes();
    }
    #region
    private string _usercode;
    public string UserCode
    {
        get { return _usercode; }
        set { _usercode = value; }
    }
    private string _p_jeamt; //商品金额
    private string _p_jfamt; //商品积分
    private string _userje;  //可用余额
    private string _shouldpay; //待支付金额




    private string _fare;    //运费
    private string _paymethod;//支付方式
    private string _bank;//银行列表

    private string _byzd12;//信用额度
    private string _dqje_1;//账户结余

    public string DQJE_1
    {
        get { return _dqje_1; }
        set { _dqje_1 = value; }
    }

    public string BYZD12
    {
        get { return _byzd12; }
        set { _byzd12 = value; }
    }



    public string P_JeAmt
    {
        set { _p_jeamt = value; }
        get { return _p_jeamt; }
    }
    public string P_JfAmt
    {
        set { _p_jfamt = value; }
        get { return _p_jfamt; }
    }
    public string UserJe
    {
        set { _userje = value; }
        get { return _userje; }
    }
    public string Fare
    {
        set { _fare = value; }
        get { return _fare; }
    }
    public string ShouldPay
    {
        set { _shouldpay = value; }
        get { return _shouldpay; }
    }
    public string PayMethod
    {
        set { _paymethod = value; }
        get { return _paymethod; }
    }
    public string Bank
    {
        set { _bank = value; }
        get { return _bank; }
    }
    #endregion
    protected void Page_Load(object sender, EventArgs e)
    {
        Page.Title = BasePage.WebTitle;
        if (!HttpContext.Current.User.Identity.IsAuthenticated)
        {
            Response.Redirect("../Users/Login.aspx");
        }
        if (int.Parse(Session["Step"].ToString()) < 2)
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert(\"商品信息已经改变，请重新选择物流方式!\")", true);
            Response.Redirect("OrderAddress.aspx");
        }
        else
        {
            UserCode = BasePage.GetValue(0);
            Init_Jeinfo();
            Init_PayMethod();
            //Init_Bank();
            Session["Step"] = "3";
        }
        if (Convert.ToDecimal(BYZD12) <= 0)
        {
            this.Panel1.Visible = false;
        
        }
        
    }
    #region 初始化金额信息




    private void Init_Jeinfo()
    {
        Model.V_CUSTOMER_ADDRESS address = new Model.V_CUSTOMER_ADDRESS();
        if (Session["Transport"] != null)
        {
            address = (Model.V_CUSTOMER_ADDRESS)Session["Transport"];
            Fare = address.WLFY.ToString("F");
        }
        else
        {
            ScriptManager.RegisterStartupScript(this, this.GetType(), "", "alert(\"请选择配送方式!\");window.location.href=\"OrderAddress.aspx\";", true);
            return;
        }
        List<Model.BUYPOCKETDETAIL> buyinfo = new List<Model.BUYPOCKETDETAIL>();
        BLL.BUYPOCKETDETAIL bll_cart = new BLL.BUYPOCKETDETAIL();
        buyinfo = bll_cart.GetAllList(UserCode);
        decimal je_amt = 0;
        decimal jf_amt = 0;
        decimal cc = 0;//需要支付金额 je_amt+Fare
        foreach (Model.BUYPOCKETDETAIL buy in buyinfo)
        {
            je_amt += buy.BPD_AAMT;
            jf_amt += buy.BPD_ITG;
        }
        P_JeAmt = je_amt.ToString("F");
        P_JfAmt = jf_amt.ToString("F");
        cc = je_amt + address.WLFY;
        ShouldPay = cc.ToString("F");
        //取可用余额



        BLL.V_VIPSET bll_vipset = new BLL.V_VIPSET();
        Model.V_VIPSET vipset = bll_vipset.GetModelByGKDM(UserCode);

        Model.V_VIP_ACCOUNT account = new Model.V_VIP_ACCOUNT();
        account = new BLL.V_VIP_ACCOUNT().GetModel(vipset.DM);

        BYZD12 = vipset.BYZD12.ToString("F");
        if (account != null)
        {
            DQJE_1 = account.DQJE_1.ToString("F");
            UserJe = (account.DQJE_1+Convert.ToDecimal(BYZD12)).ToString("F");
        }

    }
    #endregion

    #region  初始化支付方式




    private void Init_PayMethod()
    {
        StringBuilder Sb = new StringBuilder();
        string where = " and PT_ONLINE=1";
        BLL.PAYTYPE paytype = new BLL.PAYTYPE();
        DataSet ds = paytype.GetPatTypeByWhere(where);
        if (ds.Tables.Count > 0)
        {
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                Sb.Append("<li><img src=\"../images/" + row["PA_LOGO"] + "\" />");
                Sb.Append("<span>");
                Sb.Append("<input name=\"radiobutton\" type=\"radio\" disabled=\"disabled\" value=\"" + row["PT_CODE"] + "\" onclick=\"ChoseBank(this)\" />");
                Sb.Append("<span>" + row["PT_NAME"] + "</span></span></li>");
            }
            
            PayMethod = Sb.ToString();
        }
    }
    #endregion
    #region 初始化银行




    private void Init_Bank()
    {
        StringBuilder Sb = new StringBuilder();
        string where = " and PT_Bank=1";
        BLL.PAYTYPE paytype = new BLL.PAYTYPE();
        DataSet ds = paytype.GetPatTypeByWhere(where);
        if (ds.Tables.Count > 0)
        {
            Sb.Append("<table id=\"BankList\" style=\"display:none\">");
            foreach (DataRow row in ds.Tables[0].Rows)
            {
                Sb.Append("<tr><td>");
                Sb.Append("<table><tr><td>");
                Sb.Append("<input name=\"radionbank\" type=\"radio\" value=\"" + row["PT_CODE"] + "\"  onclick=\"ChooseBank(this)\" />");
                Sb.Append("</td><td>");
                Sb.Append("<span>" + row["PT_NAME"] + "</span>");
                Sb.Append("</td></tr></table>");
                Sb.Append("</td>");
                Sb.Append("<td>");
                Sb.Append("<span>" + row["PT_TEXT1"] + "</span>");
                Sb.Append("</td></tr>");
            }
            Sb.Append("</table>");
            Bank = Sb.ToString();
        }
    }
    #endregion
    
}
